package com.hsjk.szwj.module.train.dal.mysql.product;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hsjk.szwj.framework.common.pojo.PageResult;
import com.hsjk.szwj.framework.mybatis.core.mapper.BaseMapperX;
import com.hsjk.szwj.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminProductSkuPageReqVO;
import com.hsjk.szwj.module.train.controller.admin.vo.AdminProductSkuPageRespVO;
import com.hsjk.szwj.module.train.dal.dataobject.product.ProductSkuDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.Arrays;
import java.util.List;

@Mapper
public interface IProductSkuMapper extends BaseMapperX<ProductSkuDO> {

    default List<ProductSkuDO> selectListBySpuId(Long spuId) {
        return selectList(new LambdaQueryWrapperX<ProductSkuDO>()
                .eq(ProductSkuDO::getSpuId, spuId)
                .orderByDesc(ProductSkuDO::getCreateTime));
    }

    default PageResult<ProductSkuDO> selectPage(AdminProductSkuPageReqVO reqVO) {
        LambdaQueryWrapperX<ProductSkuDO> wrapperX = new LambdaQueryWrapperX<>();
        if (reqVO.getSpuId() != null) {
            wrapperX.eq(ProductSkuDO::getSpuId, reqVO.getSpuId());
        }
        return selectPage(reqVO, wrapperX
                .orderByDesc(Arrays.asList(ProductSkuDO::getCreateTime, ProductSkuDO::getCreateTime)));
    }

    IPage<AdminProductSkuPageRespVO> getProductSkuPageList(Page<AdminProductSkuPageReqVO> page,
                                                           @Param("param") AdminProductSkuPageReqVO reqVO);
}
